import 'package:aio/aio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/http/bean/wroks/attachment_bean.dart';
import 'package:app/src/http/bean/wroks/contract_bean.dart';
import 'package:app/src/http/bean/wroks/customers_copyInfo.dart';
import 'package:app/src/ui/app_ui.dart';
import 'package:app/src/ui/route/helper/route_helper.dart';
import 'package:app/src/ui/route/works/public/items/ui_base.dart';
import 'package:app/src/ui/route/works/public/items/ui_card.dart';
import 'package:app/src/utils/image_path_utils.dart';

///图片展示
class UiImage {

  static double _width=100;//图片宽
  static double _height=60;//图片高

  ///title 标题
  static Widget build(BuildContext context, List<String>? PicList,
      {String? title}) {
    if (StringUtils.isEmpty(PicList)) {
      return AppUi.getEmptyView();
    }
    if (StringUtils.isEmpty(title)) {
      title = AppStrings.of(context).GraphicEvidence; //图片证据
    }
    List<Widget> children = [];
    children.add(UiBase.title(context, title, bottom: 8));
    children.add(_images(context, PicList!));
    var column = UiBase.column(context, children);
    var card = UiCard.build(context, column);
    return card;
  }

  static Widget _images(BuildContext context, List<String> PicList) {
    var listView = ListView.builder(
      scrollDirection: Axis.horizontal,
      //Axis.horizontal水平方向;Axis.vertical垂直方向（默认）
      //mainAxisExtent主轴方向元素的固定高度。
      itemCount: PicList.length,
      itemBuilder: (context, index) {
        var src = PicList[index];
        var image = Image.network(
          src,
          key: Key("$src"),
          width: _width,
          height: _height,
          fit: BoxFit.cover,
        );
        var inkWell = InkWell(
          child: image,
          onTap: () {
            //图片预览
            AppRouteHelper.goPreviewImagesRoute(context, PicList, index: index);
          },
        );
        return Container(
          child: inkWell,
          margin: EdgeInsets.only(right: 6),
        );
      },
      physics: BouncingScrollPhysics(),
    );
    return Container(
      child: listView,
      height: _height,
    );
  }
}
